package com.kakarote.core.config;

import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.Producer;
import com.kakarote.core.entity.MqProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * 项目基础配置类
 *
 * @author zhangzhiwei
 */
@Configuration
@EnableFeignClients(basePackages = {"com.kakarote.core.feign"})
@ComponentScan(basePackages = {"com.kakarote.core"})
@EnableConfigurationProperties(MqProperties.class)
public class CommonWebAutoConfiguration {

    @Autowired
    private MqProperties mqProperties;

    @Bean
    public Producer createProducer() {
        Producer producer = ONSFactory.createProducer(mqProperties.getProperties());
        producer.start();
        return producer;
    }
}
